<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>管理员管理页面</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport"
            content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../public/css/font.css">
        <link rel="stylesheet" href="../../public/css/xadmin.css">
        <script type="text/javascript" src="../../public/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../public/js/xadmin.js"></script>
        <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
        <!--[if lt IE 9]>
                <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
                <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
            <![endif]-->
    </head>

    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label for="idb" class="layui-form-label">
                            <span class="x-red">*</span>参与用户开始学号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="idb" name="idb" required="" lay-verify="idb"
                                autocomplete="off" class="layui-input" value="2001200001">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>参与用户开始学号(包括此学号)
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="ide" class="layui-form-label">
                            <span class="x-red">*</span>参与用户结束学号
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="ide" name="ide" required="" lay-verify="ide"
                                autocomplete="off" class="layui-input" value="2001205000">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>参与用户结束学号(不包括此学号)
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="timeb" class="layui-form-label">
                            <span class="x-red">*</span>开始时间
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="timeb" name="timeb" required="" lay-verify="timeb"
                                autocomplete="off" class="layui-input" value="{{.timeb}}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>开始时间, 格式为yyyy-MM-dd hh:mm:ss
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="timee" class="layui-form-label">
                            <span class="x-red">*</span>结束时间
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="timee" name="timee" required="" lay-verify="timee"
                                autocomplete="off" class="layui-input" value="{{.timee}}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>结束时间, 格式为yyyy-MM-dd hh:mm:ss
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="timedate" class="layui-form-label">
                            <span class="x-red">*</span>记录日期
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="timedate" name="timedate" required="" lay-verify="timedate"
                                autocomplete="off" class="layui-input" value="{{.timedate}}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <span class="x-red">*</span>记录日期, 格式为yyyy-MM-dd
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label">
                        </label>
                        <button class="layui-btn" lay-filter="init" lay-submit="">
                            提交
                        </button>
                    </div>
                </form>
                
                <button class="layui-btn" title="查看状态" onclick="spikestat()" href="javascript:;">查看状态</button>
                <button class="layui-btn" title="手动停止订单处理" onclick="spikeclear()" href="javascript:;">手动停止订单处理</button>
            </div>
        </div>
        <script src="https://cdn.bootcdn.net/ajax/libs/jsencrypt/3.0.0-rc.1/jsencrypt.js"></script>
        <script>
        var PUBLIC_KEY = '{{.pubkey}}';
        var encrypt = new JSEncrypt();
        encrypt.setPublicKey('-----BEGIN PUBLIC KEY-----' + PUBLIC_KEY + '-----END PUBLIC KEY-----');
        layui.use(['form', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                //自定义验证规则
                form.verify({
                    idb: function (value) {
                        if (value.length < 5 || value.length > 10) {
                            return '学号范围5-10个字符';
                        }
                    },
                    ide: function (value) {
                        if (value.length < 5 || value.length > 10) {
                            return '学号范围5-10个字符';
                        }
                    },
                    timeb: function(value) {
                        var date = new Date(value);
                        var y = date.getFullYear();
                        var M = (date.getMonth() + 1).toString();
                        var d = (date.getDate()).toString();
                        var h = (date.getHours()).toString();
                        var m = (date.getMinutes()).toString();
                        var s = (date.getSeconds()).toString();
                        if (M.length == 1) { 
                            M = "0" + M; 
                        }
                        if (d.length == 1) { 
                            d = "0" + d; 
                        }
                        if (h.length == 1) { 
                            h = "0" + h; 
                        }
                        if (m.length == 1) { 
                            m = "0" + m; 
                        }
                        if (s.length == 1) { 
                            s = "0" + s; 
                        }
                        var newtime = y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s;
                        if (value != newtime) {
                            return '时间格式为: yyyy-MM-dd hh:mm:ss';
                        }
                    },
                    timee: function(value) {
                        var date = new Date(value);
                        var y = date.getFullYear();
                        var M = (date.getMonth() + 1).toString();
                        var d = (date.getDate()).toString();
                        var h = (date.getHours()).toString();
                        var m = (date.getMinutes()).toString();
                        var s = (date.getSeconds()).toString();
                        if (M.length == 1) { 
                            M = "0" + M; 
                        }
                        if (d.length == 1) { 
                            d = "0" + d; 
                        }
                        if (h.length == 1) { 
                            h = "0" + h; 
                        }
                        if (m.length == 1) { 
                            m = "0" + m; 
                        }
                        if (s.length == 1) { 
                            s = "0" + s; 
                        }
                        var newtime = y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s;
                        if (value != newtime) {
                            return '时间格式为: yyyy-MM-dd hh:mm:ss';
                        }
                    },
                    timedate: function(value) {
                        var date = new Date(value);
                        var y = date.getFullYear(); 
                        var m = (date.getMonth() + 1).toString(); 
                        var d = (date.getDate()).toString();  
                        if (m.length == 1) { 
                            m = "0" + m; 
                        } 
                        if (d.length == 1) { 
                            d = "0" + d; 
                        }
                        var newtime = y + "-" + m + "-" + d;
                        if (value != newtime) {
                            return '日期格式为: yyyy-MM-dd';
                        }
                    },
                });

                //监听提交
                form.on('submit(init)',
                    function (data) {
                        console.log(data);
                        //发异步，把数据提交给php
                        $.ajax({
                            url: "./spikeman/init",
                            type: "post",
                            data: {data: encrypt.encrypt(JSON.stringify({
                                b: data.field.idb,
                                e: data.field.ide,
                                tb: data.field.timeb,
                                te: data.field.timee,
                                td: data.field.timedate,
                            }))},
                            dataType: "json",
                            success: function (resp) {
                                console.log(resp);
                                if (resp.status) {
                                    layer.alert("提交成功", { icon: 6 });
                                } else {
                                    layer.alert("提交失败", { icon: 2 });
                                }
                            }
                        });
                        return false;
                    }
                );
            }
        );
        function spikestat() {
            $.ajax({
                url: "./spikeman/stat",
                type: "post",
                dataType: "json",
                success: function (resp) {
                    console.log(resp);
                    layer.msg('返回消息: ' + JSON.stringify(resp),{icon:1});
                    // if (resp.status) {
                    //     $(obj).parents("tr").remove();
                    //     layer.msg('已删除!',{icon:1,time:1000});
                    // } else {
                    //     layer.msg('删除失败:' + resp.msg,{icon:2,time:1000});
                    // }
                },
                complete:function (resp) {
                    console.log(resp);
                },
            });
        }
        function spikeclear() {
            $.ajax({
                url: "./spikeman/clear",
                type: "post",
                dataType: "json",
                success: function (resp) {
                    console.log(resp);
                    layer.msg('返回消息: ' + JSON.stringify(resp),{icon:1});
                    // if (resp.status) {
                    //     $(obj).parents("tr").remove();
                    //     layer.msg('已删除!',{icon:1,time:1000});
                    // } else {
                    //     layer.msg('删除失败:' + resp.msg,{icon:2,time:1000});
                    // }
                },
                complete:function (resp) {
                    console.log(resp);
                },
            });
        }
        </script>
        <script>
        var _hmt = _hmt || []; (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
        </script>
    </body>

</html>